package com.wst.system.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wst.system.security.IsAdmin;
import com.wst.system.security.entity.SysRoleEntity;
import com.wst.system.security.entity.SysRoleMenuEntity;
import com.wst.system.security.entity.vo.SysRoleMenuEntityVo;
import com.wst.system.server.entity.vo.IdVo;
import com.wst.system.server.service.SysRoleMenuService;
import com.wst.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/sysrolemenu")
public class SysRoleMenuController {

    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    @IsAdmin
    @PostMapping("/save")
    public JSONObject saveSysRoleMenu(@RequestBody SysRoleMenuEntityVo vo){
        sysRoleMenuService.save(vo);
        return ResultUtil.successInfo();
    }

    @IsAdmin
    @PostMapping("/getcheckids")
    public JSONObject getCheckIds(@RequestBody IdVo idVo){
        List<SysRoleMenuEntity> list=sysRoleMenuService.getSysRoleMenuEntityRid(idVo.getId());
        List<Integer> ids=new ArrayList<>();
        if(list!=null && list.size()>0){
            ids=list.stream().map(SysRoleMenuEntity::getMenuId).collect(Collectors.toList());
        }
        return ResultUtil.successInfo(ids);
    }

}
